package b1.scenes.fight
{
	import b1.controls.basic.BasicMessage;
	import b1.net.ResourceHelper;
	import b1.conifg.*;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class PlayTime extends Sprite
	{
		
		private var playTimeBackground:Sprite;
		private var textField:TextField;
		private var tip:BasicMessage;
		
		public function PlayTime()
		{
			super();
			var PlayTimeBackground:Class = ResourceHelper.getInstance().getClassByName("TimeTipBackground");
			playTimeBackground = new PlayTimeBackground();
			playTimeBackground.width = 50;
			playTimeBackground.scaleY = playTimeBackground.scaleX;
			addChild(playTimeBackground);
			
			textField = new TextField();
			textField.selectable = false;
        	textField.autoSize = TextFieldAutoSize.CENTER;
			textField.defaultTextFormat = new TextFormat("微软雅黑", 20);
			addChild(textField);
			
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		public function update(timeLeft:int):void
		{
			textField.text = timeLeft.toString();
			textField.x = (playTimeBackground.width - textField.width) / 2 - 2;
			textField.y = (this.height - textField.height) / 4;
		}
		
		public function onMouseOver(event:MouseEvent):void
		{
			var tipContent:String = "此次战斗剩余时间";
			tip = new BasicMessage(18 * tipContent.length, 25, tipContent, 0x8080FF); 
			tip.x = this.x + (this.width - tip.width) / 2;
			tip.y = this.y + playTimeBackground.height + 5;
			this.parent.addChild(tip);
		}
		
		public function onMouseOut(event:MouseEvent):void
		{
			if (null != tip && tip.parent != null)
			{
				tip.parent.removeChild(tip);
			}
		}
		
	}
}